from __future__ import absolute_import, unicode_literals
import os
import celery
import raven
from raven.contrib.celery import register_signal, register_logger_signal

class Celery(celery.Celery):
    pass

    # def on_configure(self):
    #     client = raven.Client('http://a946b23f636649be9558a8a5cef41f81:3aa102aabdee4a24a01cff7bb4dd58d8@sentry.jiafu.one/2')
    #
    #     # register a custom filter to filter out duplicate logs
    #     register_logger_signal(client)
    #
    #     # hook into the Celery error handler
    #     register_signal(client)

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jiafu_server.settings')

app = Celery('jiafu_server')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))